{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Severals approaches could be used.\n",
    "\n",
    "-----------------\n",
    "\n",
    "The lazzy one: use another format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "AlignIO.write(my_alignments, \"mixed.fa\", \"fasta\")\n",
    "os.system(\"head mixed.fa\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> \\>toto <unknown description>   \n",
    "> ACTGCTAGCTAG   \n",
    "> \\>titi <unknown description>   \n",
    "> ACT-CTAGCTAG   \n",
    "> \\>tata <unknown description>   \n",
    "> ACTGCTAGDTAG   \n",
    "> \\>PGSC0003DMP400022612   \n",
    "> \\------------------------------------------------------------   \n",
    "> \\------------------------------------------------------------   \n",
    "> \\-------MLPFESIEEASMSLGRNLTFGETLWF---------------------------   \n",
    "\n",
    "\n",
    "\n",
    "But the lazzy is usually not the best one (the fasta format is ambigous) and probably we had good reason to choose the 'phylip' format initialy! \n",
    "\n",
    "---------------------------\n",
    "The reformat approach\n",
    "\n",
    "Let's just extract the variable part of the id (the end) end paste it in the begining of the id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for seqR in my_alignments[1]:\n",
    "   seqR.id = seqR.id[-10:] + \"-\" + seqR.id\n",
    "\n",
    "print my_alignments[1][1]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> ID: P400060824-PGSC0003DMP400060824   \n",
    "> Name: <unknown name>   \n",
    "> Description: PGSC0003DMP400060824   \n",
    "> Number of features: 0   \n",
    "> Seq('---------------MQIFVKTLTGKTITLEVESSDTIDNVKAKIQDKEGIPPD...GGF', SingleLetterAlphabet())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "AlignIO.write(my_alignments, \"mixed.phy\", \"phylip\")\n",
    "os.system(\"head mixed.phy\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> &nbsp; 3 &nbsp; 12   \n",
    "> toto &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ACTGCTAGCT AG   \n",
    "> titi &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ACT-CTAGCT AG   \n",
    "> tata &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ACTGCTAGDT AG   \n",
    "> &nbsp; 10 &nbsp; 1294   \n",
    "> P400022612 ---------- ---------- ---------- ---------- ----------   \n",
    "> P400060824 ---------- -----MQIFV KTLTGKTITL EVESSDTIDN VKAKIQDKEG   \n",
    "> P400067339 ---------- -----MGVWK DSNYGKGVII GVIDT--GIL PDHPSFSDVG   \n",
    "> P400027454 MPHPTQVVAL LKAQQIRHVR LFNADRGMLL ALANTGIKVA VSVPNEQILG   \n",
    "> P400028584 ---------- --------MS TSVEPNGAVL ---------- ----LDSTAG   \n",
    "\n",
    "\n",
    "----------------------\n",
    "The best appraoch\n",
    "\n",
    "\n",
    "This a common issue so a specific format have already been developped. `phylip-relaxed` format is a relaxed interpretation of the PHYLIP format which allows long names."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "aln_patato = AlignIO.read(\"data/muscle-patato_pep.clw\", \"clustal\")\n",
    "my_alignments2 = [align1, aln_patato]\n",
    "AlignIO.write(my_alignments2, \"mixed2.phy\", \"phylip-relaxed\")\n",
    "os.system(\"head mixed2.phy\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> &nbsp; 3 12   \n",
    "> toto  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ACTGCTAGCT AG   \n",
    "> titi  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ACT-CTAGCT AG   \n",
    "> tata  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ACTGCTAGDT AG   \n",
    "> &nbsp; 10 1294   \n",
    "> PGSC0003DMP400022612  ---------- ---------- ---------- ---------- ----------   \n",
    "> PGSC0003DMP400060824  ---------- -----MQIFV KTLTGKTITL EVESSDTIDN VKAKIQDKEG   \n",
    "> PGSC0003DMP400067339  ---------- -----MGVWK DSNYGKGVII GVIDT--GIL PDHPSFSDVG   \n",
    "> PGSC0003DMP400027454  MPHPTQVVAL LKAQQIRHVR LFNADRGMLL ALANTGIKVA VSVPNEQILG   \n",
    "> PGSC0003DMP400028584  ---------- --------MS TSVEPNGAVL ---------- ----LDSTAG"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 0
}
